// /////////////////////////////////////////////////////////////////////////////
//
// Name:            DataStore.h
// Author:          Michael Bartsch (ZCCdark203)
//
// Desc :           Declaration of the DataStore class.
//
// License:         Copyright (C) 2009 Michael Bartsch and Contributors
//
//                  This program is free software: you can redistribute it
//                  and/or modify it under the terms of the zlib/libpng License.
//                  See main.cpp for conditions of distribution and use.
//
// /////////////////////////////////////////////////////////////////////////////

#ifndef __DATASTORE_H__
#define __DATASTORE_H__

// Include files
#include "../dependencies.h"
#include "DataStack.h"

// Forward declarations
class DataStack;


// DataStore class
//! The DataStore class manages the DataStacks that are being used by the framework.
class DataStore : public ReferenceCounted
{
public:

    // Initialisation and deinitialisation
    //! Constructor
    DataStore();
    //! Deconstructor
    ~DataStore();

    //! Initialises the DataStore.
    void init();
    //! Clears the DataStore.
    void clear();

    // Reference counting
    //! Increases the reference counter.
    //! @note This is a dummy function.
    void grab();
    //! Decreases the reference counter.
    //! @note This is a dummy function.
    void drop();

    // Methods
    //! Adds the given DataStack to the DataStore.
    //! @param stack         Pointer to the DataStack to add.
    //! @return True if addition was successful, false if addition was a failure.
    bool addDataStack(DataStack *stack);
    //! Creates (and adds) a DataStack with the given name.
    //! @param name          Name of the DataStack.
    //! @param grab          Should the DataStore add the loaded DataStack to the internal list?
    //! @return Pointer to the DataStack on success, NULL on failure.
    DataStack* createDataStack(const std::string &name, bool grab = true);

    //! Gets the DataStack with the given ID.
    //! @return Pointer to the DataStack if found, else NULL.
    DataStack* getDataStack(const u32 id);
    //! Gets the DataStack with the given name.
    //! @return Pointer to the DataStack if found, else NULL.
    DataStack* getDataStack(const std::string &name);

    //! Removes all DataStacks from the DataStore.
    void removeDataStacks();
    //! Removes the given DataStack.
    //! @param stack         Pointer to the DataStack to remove.
    //! @return True if removal was successful, false if removal was a failure.
    bool removeDataStack(DataStack *stack);
    //! Removes the given DataStack with the given ID.
    //! @param id            ID of the DataStack to remove.
    //! @return True if removal was successful, false if removal was a failure.
    bool removeDataStack(const u32 id);
    //! Removes the given DataStack with the given name.
    //! @param name          Name of the DataStack to remove.
    //! @return True if removal was successful, false if removal was a failure.
    bool removeDataStack(const std::string &name);

private:

    // Normal members
    std::vector<DataStack*> mStacks;

};

#endif
